package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.http.response.ReportTypeBean;
import com.qf.flash.mvp.contract.ReportContract;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

/**
 * 描述:
 * 2020/3/27 14:59
 */
public class ReportPresenter extends BasePresenter<ReportContract.View> implements ReportContract.Presenter {
    @Override
    public void getReportType() {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .REPORT_TYPE()
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<List<ReportTypeBean>>(mRootView) {
                    @Override
                    public void onSuccess(List<ReportTypeBean> reportTypeBeans) {
                        mRootView.setReportTypeData(reportTypeBeans);
                    }
                })
        );
    }

    @Override
    public void reportSomeBody(String reportUerId, String infoID) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .REPORT_SOMEBODY(uid, reportUerId, infoID)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object obj) {
                        mRootView.reportSomeBodySuccess();
                    }
                })
        );
    }

    @Override
    public void addBlack(String id) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .BLACK_FRIEND(uid, id)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object obj) {
                        mRootView.addBlackFriendSuccess();
                    }
                })
        );
    }
    @Override
    public void cancelBlack(String id) {
        String uid = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .CANCEL_BALCK(uid, id)
                .compose(RxUtils.handleResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<Object>(mRootView) {
                    @Override
                    public void onSuccess(Object obj) {
                        mRootView.cancelBlackFriendSuccess();
                    }
                })
        );
    }
}
